package com.ztom.v2;

/**
 * @author ZhangTao
 */
public class Code98SortColors {

    public void sortColors(int[] nums) {
        if (nums == null || nums.length <= 1) {
            return;
        }
        int l = -1;
        int r = nums.length;
        int num = 1;
        int index = 0;
        while (index < r) {
            if (nums[index] < num) {
                swap(nums, index++, ++l);
            } else if (nums[index] > num) {
                swap(nums, index, --r);
            } else {
                index++;
            }
        }
    }

    public void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
